package homework;

public class StudentGroup {
	String groupSubject;
	Student [] students;
	int freePlaces;
	
	 StudentGroup()
	{
		freePlaces = 5;
		students = new Student[freePlaces];
	}
	 StudentGroup(String subject)
	 {
		 this();
		 this.groupSubject = subject;
	 }
	 void addStudent(Student s) 
	 {
		 if(s.subject == this.groupSubject && this.freePlaces>=0)
		 {
			 for(int i = 0; i<students.length; i++)
			 {
				 s = students[i];
				 this.freePlaces--;
			 }
		 }
	 }
	 void emptyGroup()
	 {
		 freePlaces = 5;
		 students = new Student[freePlaces];
	 }
	 void theBestStudent() 
	 {
		 double maxGrade = 0;
		 int maxGradeIdx = 0;
		 for(int i = 0; i<students.length; i++)
		 {
			 if(maxGrade<=students[i].grade)
			 {
				 students[i].grade = maxGrade;
				 maxGradeIdx = i;
			 }
		 }
		 System.out.println(" The best student is: " +  students[maxGradeIdx].name);
	 }
	 void printStudentsInGroup()
	 {
		 for(int i = 0; i<students.length; i++)
		 {
			 if(students[i]!=null)
			 {
			 System.out.println("Name: " + students[i].name);
			 System.out.println("Year in college: " + students[i].yearInCollege);
			 System.out.println("Grade: " + students[i].grade);
			 System.out.println("Age: " + students[i].age);
			 System.out.println("Amount: " + students[i].money);
			 System.out.println("Subject in college: " + students[i].subject);
			 }
		 }
		 
	 }
}
